package com.stx.day0910;

import java.util.Arrays;

/**
 * packageName com.stx.day0910
 *
 * @author YangYi
 * @className ArrayDemo
 * @date 2025/9/10
 * @description TODO
 */
public class ArrayDemo {
    public static void main(String[] args){
        /**
         * 数组定义：type[] var-name;
         */
        // 第一种：数组类型[] 数组名称 = new 数组类型[固定长度];
        int[] cars = new int[46];
        for(int i = 0; i< 3;i++){
            System.out.println(cars[i]);
        }
        // 第二种：数组类型[] 数组名称 = new 数组类型[]{值1，值2....};
        byte[] array_byte = new byte[]{1,2,4,5,6};
        // 第三种：数组类型[] 数组名称 = {}；
        double[] array_double = {1,2,6,0};
        
        // 如何获取数组里的最大值
        int[] room = new int[]{10,5,-6,-1,9,-12};
        int maxNum = getMax(room);
        System.out.println("数组最大值："+maxNum);
        // 获取数组的最小值
        int minNum = getMin(room);
        System.out.println(minNum);

        boolean[] bo_array = new boolean[5];
        for(int i=0;i<5;i++){
            System.out.println(bo_array[i]);
        }
        for(boolean bo:bo_array){
            System.out.println(bo);
        }

        int[] bus = new int[5];
        bus[0] = 5;
        bus[1] = 9;
        bus[2] = 7;
        bus[3] = 2;
        bus[4] = 4;
        for(int i = 0;i<bus.length;i++){
            System.out.println(bus[i]);
        }
        // 数组复制
        int[] newBus = Arrays.copyOf(bus,5);
        for(int i = 0;i<5;i++){
            System.out.println(newBus[i]);
        }

    }
    public static int getMin(int[] room){
        int min_num=room[0];
        for (int i = 0; i <room.length ; i++) {
            if (min_num>room[i]){
                min_num=room[i];
            }

        }
        return min_num;
    }

    /**
     * 获取数组里的最大值
     * @return
     */
    public static int getMax(int[] room){
        int maxNum = room[0];
        // 循环遍历数组
        for(int i = 1;i < room.length;i++){
            if(room[i] > maxNum){
                maxNum = room[i];
            }
        }
        return maxNum;
    }
}
